import os
import json
import requests
from .  import wppAction

config = wppAction.read_jsonFile("autoStartConfig.json")

if config["wpp"] == True:
    os.startfile("wppRunner.exe")
if config["easyDesktop"] == True:
    os.startfile("easyDesktop.exe")

chars_data = wppAction.read_jsonFile("char/chars.json")
for char_id in chars_data:
    if chars_data[char_id]["create_local"] != False:
        check_r = requests.get(f"http://127.0.0.1:8001/content/get/wpp_char?cid={chars_data[char_id]["net_id"]}")
        if check_r.status_code == 200:
            content = json.loads(str(check_r.content,"utf-8"))
            if content["success"]==True:
                v = content["data"]["content"]["v"]
                if int(chars_data[char_id]["v"]) < int(v):
                    wppAction.download_char(chars_data[char_id]["net_id"])
if config["char"]==True:
    os.startfile("char_runner.exe")
            